home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / debugHelper / OpenGL.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  50.7 KB  |  1,959 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*****************************************************************************
  18.  *
  19.  * Defines debug functions for all OpenGL calls made by Inventor.
  20.  *
  21. /*****************************************************************************/
  22.  
  23. #include <GL/gl.h>
  24. #include <GL/glu.h>
  25. #include <GL/glx.h>
  26. #include <stdio.h>
  27. #include <dlfcn.h>
  28.  
  29. /* Pointers to the GLU, and GL (which contains GLX) DSO's */
  30. static const char *gl = "/usr/lib/libGL.so";
  31. static void *gl_dso = NULL;
  32. static const char *glu = "/usr/lib/libGLU.so";
  33. static void *glu_dso = NULL;
  34.  
  35. /* If this is true, generate stupid code for some stuff */
  36. static int output_code = -1;
  37.  
  38. /* This will be true if a routine is called from within another */
  39. /* routine (if an OpenGL routine calls another OpenGL routine) */
  40. static int recursing = 0;
  41.  
  42. typedef struct Lookup {
  43.     int enum_value;
  44.     char *enum_string;
  45. } Lookup;
  46.  
  47. /*
  48.  * Note: this list is sorted by enum value, so we could use a quick
  49.  * binary search to look through it...
  50.  */
  51. static Lookup gl_constants[] = {
  52. {GL_ZERO, "GL_ZERO" },
  53. {GL_ONE, "GL_ONE" },
  54. {GL_ACCUM, "GL_ACCUM"},
  55. {GL_LOAD, "GL_LOAD"},
  56. {GL_RETURN, "GL_RETURN"},
  57. {GL_MULT, "GL_MULT"},
  58. {GL_ADD, "GL_ADD"},
  59. {GL_NEVER, "GL_NEVER"},
  60. {GL_LESS, "GL_LESS"},
  61. {GL_EQUAL, "GL_EQUAL"},
  62. {GL_LEQUAL, "GL_LEQUAL"},
  63. {GL_GREATER, "GL_GREATER"},
  64. {GL_NOTEQUAL, "GL_NOTEQUAL"},
  65. {GL_GEQUAL, "GL_GEQUAL"},
  66. {GL_ALWAYS, "GL_ALWAYS"},
  67. {GL_SRC_COLOR, "GL_SRC_COLOR"},
  68. {GL_ONE_MINUS_SRC_COLOR, "GL_ONE_MINUS_SRC_COLOR"},
  69. {GL_SRC_ALPHA, "GL_SRC_ALPHA"},
  70. {GL_ONE_MINUS_SRC_ALPHA, "GL_ONE_MINUS_SRC_ALPHA"},
  71. {GL_DST_ALPHA, "GL_DST_ALPHA"},
  72. {GL_ONE_MINUS_DST_ALPHA, "GL_ONE_MINUS_DST_ALPHA"},
  73. {GL_DST_COLOR, "GL_DST_COLOR"},
  74. {GL_ONE_MINUS_DST_COLOR, "GL_ONE_MINUS_DST_COLOR"},
  75. {GL_SRC_ALPHA_SATURATE, "GL_SRC_ALPHA_SATURATE"},
  76. {GL_CLIP_PLANE0, "GL_CLIP_PLANE0"},
  77. {GL_CLIP_PLANE1, "GL_CLIP_PLANE1"},
  78. {GL_CLIP_PLANE2, "GL_CLIP_PLANE2"},
  79. {GL_CLIP_PLANE3, "GL_CLIP_PLANE3"},
  80. {GL_CLIP_PLANE4, "GL_CLIP_PLANE4"},
  81. {GL_CLIP_PLANE5, "GL_CLIP_PLANE5"},
  82. {GL_FRONT_LEFT, "GL_FRONT_LEFT"},
  83. {GL_FRONT_RIGHT, "GL_FRONT_RIGHT"},
  84. {GL_BACK_LEFT, "GL_BACK_LEFT"},
  85. {GL_BACK_RIGHT, "GL_BACK_RIGHT"},
  86. {GL_FRONT, "GL_FRONT"},
  87. {GL_BACK, "GL_BACK"},
  88. {GL_LEFT, "GL_LEFT"},
  89. {GL_RIGHT, "GL_RIGHT"},
  90. {GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK"},
  91. {GL_AUX0, "GL_AUX0"},
  92. {GL_AUX1, "GL_AUX1"},
  93. {GL_AUX2, "GL_AUX2"},
  94. {GL_AUX3, "GL_AUX3"},
  95. {GL_INVALID_ENUM, "GL_INVALID_ENUM"},
  96. {GL_INVALID_VALUE, "GL_INVALID_VALUE"},
  97. {GL_INVALID_OPERATION, "GL_INVALID_OPERATION"},
  98. {GL_STACK_OVERFLOW, "GL_STACK_OVERFLOW"},
  99. {GL_STACK_UNDERFLOW, "GL_STACK_UNDERFLOW"},
  100. {GL_OUT_OF_MEMORY, "GL_OUT_OF_MEMORY"},
  101. {GL_2D, "GL_2D"},
  102. {GL_3D, "GL_3D"},
  103. {GL_3D_COLOR, "GL_3D_COLOR"},
  104. {GL_3D_COLOR_TEXTURE, "GL_3D_COLOR_TEXTURE"},
  105. {GL_4D_COLOR_TEXTURE, "GL_4D_COLOR_TEXTURE"},
  106. {GL_PASS_THROUGH_TOKEN, "GL_PASS_THROUGH_TOKEN"},
  107. {GL_POINT_TOKEN, "GL_POINT_TOKEN"},
  108. {GL_LINE_TOKEN, "GL_LINE_TOKEN"},
  109. {GL_POLYGON_TOKEN, "GL_POLYGON_TOKEN"},
  110. {GL_BITMAP_TOKEN, "GL_BITMAP_TOKEN"},
  111. {GL_DRAW_PIXEL_TOKEN, "GL_DRAW_PIXEL_TOKEN"},
  112. {GL_COPY_PIXEL_TOKEN, "GL_COPY_PIXEL_TOKEN"},
  113. {GL_LINE_RESET_TOKEN, "GL_LINE_RESET_TOKEN"},
  114. {GL_EXP, "GL_EXP"},
  115. {GL_EXP2, "GL_EXP2"},
  116. {GL_CW, "GL_CW"},
  117. {GL_CCW, "GL_CCW"},
  118. {GL_COEFF, "GL_COEFF"},
  119. {GL_ORDER, "GL_ORDER"},
  120. {GL_DOMAIN, "GL_DOMAIN"},
  121. {GL_CURRENT_COLOR, "GL_CURRENT_COLOR"},
  122. {GL_CURRENT_INDEX, "GL_CURRENT_INDEX"},
  123. {GL_CURRENT_NORMAL, "GL_CURRENT_NORMAL"},
  124. {GL_CURRENT_TEXTURE_COORDS, "GL_CURRENT_TEXTURE_COORDS"},
  125. {GL_CURRENT_RASTER_COLOR, "GL_CURRENT_RASTER_COLOR"},
  126. {GL_CURRENT_RASTER_INDEX, "GL_CURRENT_RASTER_INDEX"},
  127. {GL_CURRENT_RASTER_TEXTURE_COORDS, "GL_CURRENT_RASTER_TEXTURE_COORDS"},
  128. {GL_CURRENT_RASTER_POSITION, "GL_CURRENT_RASTER_POSITION"},
  129. {GL_CURRENT_RASTER_POSITION_VALID, "GL_CURRENT_RASTER_POSITION_VALID"},
  130. {GL_CURRENT_RASTER_DISTANCE, "GL_CURRENT_RASTER_DISTANCE"},
  131. {GL_POINT_SMOOTH, "GL_POINT_SMOOTH"},
  132. {GL_POINT_SIZE, "GL_POINT_SIZE"},
  133. {GL_POINT_SIZE_RANGE, "GL_POINT_SIZE_RANGE"},
  134. {GL_POINT_SIZE_GRANULARITY, "GL_POINT_SIZE_GRANULARITY"},
  135. {GL_LINE_SMOOTH, "GL_LINE_SMOOTH"},
  136. {GL_LINE_WIDTH, "GL_LINE_WIDTH"},
  137. {GL_LINE_WIDTH_RANGE, "GL_LINE_WIDTH_RANGE"},
  138. {GL_LINE_WIDTH_GRANULARITY, "GL_LINE_WIDTH_GRANULARITY"},
  139. {GL_LINE_STIPPLE, "GL_LINE_STIPPLE"},
  140. {GL_LINE_STIPPLE_PATTERN, "GL_LINE_STIPPLE_PATTERN"},
  141. {GL_LINE_STIPPLE_REPEAT, "GL_LINE_STIPPLE_REPEAT"},
  142. {GL_LIST_MODE, "GL_LIST_MODE"},
  143. {GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING"},
  144. {GL_LIST_BASE, "GL_LIST_BASE"},
  145. {GL_LIST_INDEX, "GL_LIST_INDEX"},
  146. {GL_POLYGON_MODE, "GL_POLYGON_MODE"},
  147. {GL_POLYGON_SMOOTH, "GL_POLYGON_SMOOTH"},
  148. {GL_POLYGON_STIPPLE, "GL_POLYGON_STIPPLE"},
  149. {GL_EDGE_FLAG, "GL_EDGE_FLAG"},
  150. {GL_CULL_FACE, "GL_CULL_FACE"},
  151. {GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE"},
  152. {GL_FRONT_FACE, "GL_FRONT_FACE"},
  153. {GL_LIGHTING, "GL_LIGHTING"},
  154. {GL_LIGHT_MODEL_LOCAL_VIEWER, "GL_LIGHT_MODEL_LOCAL_VIEWER"},
  155. {GL_LIGHT_MODEL_TWO_SIDE, "GL_LIGHT_MODEL_TWO_SIDE"},
  156. {GL_LIGHT_MODEL_AMBIENT, "GL_LIGHT_MODEL_AMBIENT"},
  157. {GL_SHADE_MODEL, "GL_SHADE_MODEL"},
  158. {GL_COLOR_MATERIAL_FACE, "GL_COLOR_MATERIAL_FACE"},
  159. {GL_COLOR_MATERIAL_PARAMETER, "GL_COLOR_MATERIAL_PARAMETER"},
  160. {GL_COLOR_MATERIAL, "GL_COLOR_MATERIAL"},
  161. {GL_FOG, "GL_FOG"},
  162. {GL_FOG_INDEX, "GL_FOG_INDEX"},
  163. {GL_FOG_DENSITY, "GL_FOG_DENSITY"},
  164. {GL_FOG_START, "GL_FOG_START"},
  165. {GL_FOG_END, "GL_FOG_END"},
  166. {GL_FOG_MODE, "GL_FOG_MODE"},
  167. {GL_FOG_COLOR, "GL_FOG_COLOR"},
  168. {GL_DEPTH_RANGE, "GL_DEPTH_RANGE"},
  169. {GL_DEPTH_TEST, "GL_DEPTH_TEST"},
  170. {GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK"},
  171. {GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE"},
  172. {GL_DEPTH_FUNC, "GL_DEPTH_FUNC"},
  173. {GL_ACCUM_CLEAR_VALUE, "GL_ACCUM_CLEAR_VALUE"},
  174. {GL_STENCIL_TEST, "GL_STENCIL_TEST"},
  175. {GL_STENCIL_CLEAR_VALUE, "GL_STENCIL_CLEAR_VALUE"},
  176. {GL_STENCIL_FUNC, "GL_STENCIL_FUNC"},
  177. {GL_STENCIL_VALUE_MASK, "GL_STENCIL_VALUE_MASK"},
  178. {GL_STENCIL_FAIL, "GL_STENCIL_FAIL"},
  179. {GL_STENCIL_PASS_DEPTH_FAIL, "GL_STENCIL_PASS_DEPTH_FAIL"},
  180. {GL_STENCIL_PASS_DEPTH_PASS, "GL_STENCIL_PASS_DEPTH_PASS"},
  181. {GL_STENCIL_REF, "GL_STENCIL_REF"},
  182. {GL_STENCIL_WRITEMASK, "GL_STENCIL_WRITEMASK"},
  183. {GL_MATRIX_MODE, "GL_MATRIX_MODE"},
  184. {GL_NORMALIZE, "GL_NORMALIZE"},
  185. {GL_VIEWPORT, "GL_VIEWPORT"},
  186. {GL_MODELVIEW_STACK_DEPTH, "GL_MODELVIEW_STACK_DEPTH"},
  187. {GL_PROJECTION_STACK_DEPTH, "GL_PROJECTION_STACK_DEPTH"},
  188. {GL_TEXTURE_STACK_DEPTH, "GL_TEXTURE_STACK_DEPTH"},
  189. {GL_MODELVIEW_MATRIX, "GL_MODELVIEW_MATRIX"},
  190. {GL_PROJECTION_MATRIX, "GL_PROJECTION_MATRIX"},
  191. {GL_TEXTURE_MATRIX, "GL_TEXTURE_MATRIX"},
  192. {GL_ATTRIB_STACK_DEPTH, "GL_ATTRIB_STACK_DEPTH"},
  193. {GL_ALPHA_TEST, "GL_ALPHA_TEST"},
  194. {GL_ALPHA_TEST_FUNC, "GL_ALPHA_TEST_FUNC"},
  195. {GL_ALPHA_TEST_REF, "GL_ALPHA_TEST_REF"},
  196. {GL_DITHER, "GL_DITHER"},
  197. {GL_BLEND_DST, "GL_BLEND_DST"},
  198. {GL_BLEND_SRC, "GL_BLEND_SRC"},
  199. {GL_BLEND, "GL_BLEND"},
  200. {GL_LOGIC_OP_MODE, "GL_LOGIC_OP_MODE"},
  201. {GL_LOGIC_OP, "GL_LOGIC_OP"},
  202. {GL_AUX_BUFFERS, "GL_AUX_BUFFERS"},
  203. {GL_DRAW_BUFFER, "GL_DRAW_BUFFER"},
  204. {GL_READ_BUFFER, "GL_READ_BUFFER"},
  205. {GL_SCISSOR_BOX, "GL_SCISSOR_BOX"},
  206. {GL_SCISSOR_TEST, "GL_SCISSOR_TEST"},
  207. {GL_INDEX_CLEAR_VALUE, "GL_INDEX_CLEAR_VALUE"},
  208. {GL_INDEX_WRITEMASK, "GL_INDEX_WRITEMASK"},
  209. {GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE"},
  210. {GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK"},
  211. {GL_INDEX_MODE, "GL_INDEX_MODE"},
  212. {GL_RGBA_MODE, "GL_RGBA_MODE"},
  213. {GL_DOUBLEBUFFER, "GL_DOUBLEBUFFER"},
  214. {GL_STEREO, "GL_STEREO"},
  215. {GL_RENDER_MODE, "GL_RENDER_MODE"},
  216. {GL_PERSPECTIVE_CORRECTION_HINT, "GL_PERSPECTIVE_CORRECTION_HINT"},
  217. {GL_POINT_SMOOTH_HINT, "GL_POINT_SMOOTH_HINT"},
  218. {GL_LINE_SMOOTH_HINT, "GL_LINE_SMOOTH_HINT"},
  219. {GL_POLYGON_SMOOTH_HINT, "GL_POLYGON_SMOOTH_HINT"},
  220. {GL_FOG_HINT, "GL_FOG_HINT"},
  221. {GL_TEXTURE_GEN_S, "GL_TEXTURE_GEN_S"},
  222. {GL_TEXTURE_GEN_T, "GL_TEXTURE_GEN_T"},
  223. {GL_TEXTURE_GEN_R, "GL_TEXTURE_GEN_R"},
  224. {GL_TEXTURE_GEN_Q, "GL_TEXTURE_GEN_Q"},
  225. {GL_PIXEL_MAP_I_TO_I, "GL_PIXEL_MAP_I_TO_I"},
  226. {GL_PIXEL_MAP_S_TO_S, "GL_PIXEL_MAP_S_TO_S"},
  227. {GL_PIXEL_MAP_I_TO_R, "GL_PIXEL_MAP_I_TO_R"},
  228. {GL_PIXEL_MAP_I_TO_G, "GL_PIXEL_MAP_I_TO_G"},
  229. {GL_PIXEL_MAP_I_TO_B, "GL_PIXEL_MAP_I_TO_B"},
  230. {GL_PIXEL_MAP_I_TO_A, "GL_PIXEL_MAP_I_TO_A"},
  231. {GL_PIXEL_MAP_R_TO_R, "GL_PIXEL_MAP_R_TO_R"},
  232. {GL_PIXEL_MAP_G_TO_G, "GL_PIXEL_MAP_G_TO_G"},
  233. {GL_PIXEL_MAP_B_TO_B, "GL_PIXEL_MAP_B_TO_B"},
  234. {GL_PIXEL_MAP_A_TO_A, "GL_PIXEL_MAP_A_TO_A"},
  235. {GL_PIXEL_MAP_I_TO_I_SIZE, "GL_PIXEL_MAP_I_TO_I_SIZE"},
  236. {GL_PIXEL_MAP_S_TO_S_SIZE, "GL_PIXEL_MAP_S_TO_S_SIZE"},
  237. {GL_PIXEL_MAP_I_TO_R_SIZE, "GL_PIXEL_MAP_I_TO_R_SIZE"},
  238. {GL_PIXEL_MAP_I_TO_G_SIZE, "GL_PIXEL_MAP_I_TO_G_SIZE"},
  239. {GL_PIXEL_MAP_I_TO_B_SIZE, "GL_PIXEL_MAP_I_TO_B_SIZE"},
  240. {GL_PIXEL_MAP_I_TO_A_SIZE, "GL_PIXEL_MAP_I_TO_A_SIZE"},
  241. {GL_PIXEL_MAP_R_TO_R_SIZE, "GL_PIXEL_MAP_R_TO_R_SIZE"},
  242. {GL_PIXEL_MAP_G_TO_G_SIZE, "GL_PIXEL_MAP_G_TO_G_SIZE"},
  243. {GL_PIXEL_MAP_B_TO_B_SIZE, "GL_PIXEL_MAP_B_TO_B_SIZE"},
  244. {GL_PIXEL_MAP_A_TO_A_SIZE, "GL_PIXEL_MAP_A_TO_A_SIZE"},
  245. {GL_UNPACK_SWAP_BYTES, "GL_UNPACK_SWAP_BYTES"},
  246. {GL_UNPACK_LSB_FIRST, "GL_UNPACK_LSB_FIRST"},
  247. {GL_UNPACK_ROW_LENGTH, "GL_UNPACK_ROW_LENGTH"},
  248. {GL_UNPACK_SKIP_ROWS, "GL_UNPACK_SKIP_ROWS"},
  249. {GL_UNPACK_SKIP_PIXELS, "GL_UNPACK_SKIP_PIXELS"},
  250. {GL_UNPACK_ALIGNMENT, "GL_UNPACK_ALIGNMENT"},
  251. {GL_PACK_SWAP_BYTES, "GL_PACK_SWAP_BYTES"},
  252. {GL_PACK_LSB_FIRST, "GL_PACK_LSB_FIRST"},
  253. {GL_PACK_ROW_LENGTH, "GL_PACK_ROW_LENGTH"},
  254. {GL_PACK_SKIP_ROWS, "GL_PACK_SKIP_ROWS"},
  255. {GL_PACK_SKIP_PIXELS, "GL_PACK_SKIP_PIXELS"},
  256. {GL_PACK_ALIGNMENT, "GL_PACK_ALIGNMENT"},
  257. {GL_MAP_COLOR, "GL_MAP_COLOR"},
  258. {GL_MAP_STENCIL, "GL_MAP_STENCIL"},
  259. {GL_INDEX_SHIFT, "GL_INDEX_SHIFT"},
  260. {GL_INDEX_OFFSET, "GL_INDEX_OFFSET"},
  261. {GL_RED_SCALE, "GL_RED_SCALE"},
  262. {GL_RED_BIAS, "GL_RED_BIAS"},
  263. {GL_ZOOM_X, "GL_ZOOM_X"},
  264. {GL_ZOOM_Y, "GL_ZOOM_Y"},
  265. {GL_GREEN_SCALE, "GL_GREEN_SCALE"},
  266. {GL_GREEN_BIAS, "GL_GREEN_BIAS"},
  267. {GL_BLUE_SCALE, "GL_BLUE_SCALE"},
  268. {GL_BLUE_BIAS, "GL_BLUE_BIAS"},
  269. {GL_ALPHA_SCALE, "GL_ALPHA_SCALE"},
  270. {GL_ALPHA_BIAS, "GL_ALPHA_BIAS"},
  271. {GL_DEPTH_SCALE, "GL_DEPTH_SCALE"},
  272. {GL_DEPTH_BIAS, "GL_DEPTH_BIAS"},
  273. {GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER"},
  274. {GL_MAX_LIGHTS, "GL_MAX_LIGHTS"},
  275. {GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES"},
  276. {GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE"},
  277. {GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE"},
  278. {GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH"},
  279. {GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH"},
  280. {GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH"},
  281. {GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH"},
  282. {GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH"},
  283. {GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS"},
  284. {GL_SUBPIXEL_BITS, "GL_SUBPIXEL_BITS"},
  285. {GL_INDEX_BITS, "GL_INDEX_BITS"},
  286. {GL_RED_BITS, "GL_RED_BITS"},
  287. {GL_GREEN_BITS, "GL_GREEN_BITS"},
  288. {GL_BLUE_BITS, "GL_BLUE_BITS"},
  289. {GL_ALPHA_BITS, "GL_ALPHA_BITS"},
  290. {GL_DEPTH_BITS, "GL_DEPTH_BITS"},
  291. {GL_STENCIL_BITS, "GL_STENCIL_BITS"},
  292. {GL_ACCUM_RED_BITS, "GL_ACCUM_RED_BITS"},
  293. {GL_ACCUM_GREEN_BITS, "GL_ACCUM_GREEN_BITS"},
  294. {GL_ACCUM_BLUE_BITS, "GL_ACCUM_BLUE_BITS"},
  295. {GL_ACCUM_ALPHA_BITS, "GL_ACCUM_ALPHA_BITS"},
  296. {GL_NAME_STACK_DEPTH, "GL_NAME_STACK_DEPTH"},
  297. {GL_AUTO_NORMAL, "GL_AUTO_NORMAL"},
  298. {GL_MAP1_COLOR_4, "GL_MAP1_COLOR_4"},
  299. {GL_MAP1_INDEX, "GL_MAP1_INDEX"},
  300. {GL_MAP1_NORMAL, "GL_MAP1_NORMAL"},
  301. {GL_MAP1_TEXTURE_COORD_1, "GL_MAP1_TEXTURE_COORD_1"},
  302. {GL_MAP1_TEXTURE_COORD_2, "GL_MAP1_TEXTURE_COORD_2"},
  303. {GL_MAP1_TEXTURE_COORD_3, "GL_MAP1_TEXTURE_COORD_3"},
  304. {GL_MAP1_TEXTURE_COORD_4, "GL_MAP1_TEXTURE_COORD_4"},
  305. {GL_MAP1_VERTEX_3, "GL_MAP1_VERTEX_3"},
  306. {GL_MAP1_VERTEX_4, "GL_MAP1_VERTEX_4"},
  307. {GL_MAP2_COLOR_4, "GL_MAP2_COLOR_4"},
  308. {GL_MAP2_INDEX, "GL_MAP2_INDEX"},
  309. {GL_MAP2_NORMAL, "GL_MAP2_NORMAL"},
  310. {GL_MAP2_TEXTURE_COORD_1, "GL_MAP2_TEXTURE_COORD_1"},
  311. {GL_MAP2_TEXTURE_COORD_2, "GL_MAP2_TEXTURE_COORD_2"},
  312. {GL_MAP2_TEXTURE_COORD_3, "GL_MAP2_TEXTURE_COORD_3"},
  313. {GL_MAP2_TEXTURE_COORD_4, "GL_MAP2_TEXTURE_COORD_4"},
  314. {GL_MAP2_VERTEX_3, "GL_MAP2_VERTEX_3"},
  315. {GL_MAP2_VERTEX_4, "GL_MAP2_VERTEX_4"},
  316. {GL_MAP1_GRID_DOMAIN, "GL_MAP1_GRID_DOMAIN"},
  317. {GL_MAP1_GRID_SEGMENTS, "GL_MAP1_GRID_SEGMENTS"},
  318. {GL_MAP2_GRID_DOMAIN, "GL_MAP2_GRID_DOMAIN"},
  319. {GL_MAP2_GRID_SEGMENTS, "GL_MAP2_GRID_SEGMENTS"},
  320. {GL_TEXTURE_1D, "GL_TEXTURE_1D"},
  321. {GL_TEXTURE_2D, "GL_TEXTURE_2D"},
  322. {GL_TEXTURE_WIDTH, "GL_TEXTURE_WIDTH"},
  323. {GL_TEXTURE_HEIGHT, "GL_TEXTURE_HEIGHT"},
  324. {GL_TEXTURE_COMPONENTS, "GL_TEXTURE_COMPONENTS"},
  325. {GL_TEXTURE_BORDER_COLOR, "GL_TEXTURE_BORDER_COLOR"},
  326. {GL_TEXTURE_BORDER, "GL_TEXTURE_BORDER"},
  327. {GL_DONT_CARE, "GL_DONT_CARE"},
  328. {GL_FASTEST, "GL_FASTEST"},
  329. {GL_NICEST, "GL_NICEST"},
  330. {GL_LIGHT0, "GL_LIGHT0"},
  331. {GL_LIGHT1, "GL_LIGHT1"},
  332. {GL_LIGHT2, "GL_LIGHT2"},
  333. {GL_LIGHT3, "GL_LIGHT3"},
  334. {GL_LIGHT4, "GL_LIGHT4"},
  335. {GL_LIGHT5, "GL_LIGHT5"},
  336. {GL_LIGHT6, "GL_LIGHT6"},
  337. {GL_LIGHT7, "GL_LIGHT7"},
  338. {GL_AMBIENT, "GL_AMBIENT"},
  339. {GL_DIFFUSE, "GL_DIFFUSE"},
  340. {GL_SPECULAR, "GL_SPECULAR"},
  341. {GL_POSITION, "GL_POSITION"},
  342. {GL_SPOT_DIRECTION, "GL_SPOT_DIRECTION"},
  343. {GL_SPOT_EXPONENT, "GL_SPOT_EXPONENT"},
  344. {GL_SPOT_CUTOFF, "GL_SPOT_CUTOFF"},
  345. {GL_CONSTANT_ATTENUATION, "GL_CONSTANT_ATTENUATION"},
  346. {GL_LINEAR_ATTENUATION, "GL_LINEAR_ATTENUATION"},
  347. {GL_QUADRATIC_ATTENUATION, "GL_QUADRATIC_ATTENUATION"},
  348. {GL_COMPILE, "GL_COMPILE"},
  349. {GL_COMPILE_AND_EXECUTE, "GL_COMPILE_AND_EXECUTE"},
  350. {GL_BYTE, "GL_BYTE"},
  351. {GL_UNSIGNED_BYTE, "GL_UNSIGNED_BYTE"},
  352. {GL_SHORT, "GL_SHORT"},
  353. {GL_UNSIGNED_SHORT, "GL_UNSIGNED_SHORT"},
  354. {GL_INT, "GL_INT"},
  355. {GL_UNSIGNED_INT, "GL_UNSIGNED_INT"},
  356. {GL_FLOAT, "GL_FLOAT"},
  357. {GL_2_BYTES, "GL_2_BYTES"},
  358. {GL_3_BYTES, "GL_3_BYTES"},
  359. {GL_4_BYTES, "GL_4_BYTES"},
  360. {GL_CLEAR, "GL_CLEAR"},
  361. {GL_AND, "GL_AND"},
  362. {GL_AND_REVERSE, "GL_AND_REVERSE"},
  363. {GL_COPY, "GL_COPY"},
  364. {GL_AND_INVERTED, "GL_AND_INVERTED"},
  365. {GL_NOOP, "GL_NOOP"},
  366. {GL_XOR, "GL_XOR"},
  367. {GL_OR, "GL_OR"},
  368. {GL_NOR, "GL_NOR"},
  369. {GL_EQUIV, "GL_EQUIV"},
  370. {GL_INVERT, "GL_INVERT"},
  371. {GL_OR_REVERSE, "GL_OR_REVERSE"},
  372. {GL_COPY_INVERTED, "GL_COPY_INVERTED"},
  373. {GL_OR_INVERTED, "GL_OR_INVERTED"},
  374. {GL_NAND, "GL_NAND"},
  375. {GL_SET, "GL_SET"},
  376. {GL_EMISSION, "GL_EMISSION"},
  377. {GL_SHININESS, "GL_SHININESS"},
  378. {GL_AMBIENT_AND_DIFFUSE, "GL_AMBIENT_AND_DIFFUSE"},
  379. {GL_COLOR_INDEXES, "GL_COLOR_INDEXES"},
  380. {GL_MODELVIEW, "GL_MODELVIEW"},
  381. {GL_PROJECTION, "GL_PROJECTION"},
  382. {GL_TEXTURE, "GL_TEXTURE"},
  383. {GL_COLOR, "GL_COLOR"},
  384. {GL_DEPTH, "GL_DEPTH"},
  385. {GL_STENCIL, "GL_STENCIL"},
  386. {GL_COLOR_INDEX, "GL_COLOR_INDEX"},
  387. {GL_STENCIL_INDEX, "GL_STENCIL_INDEX"},
  388. {GL_DEPTH_COMPONENT, "GL_DEPTH_COMPONENT"},
  389. {GL_RED, "GL_RED"},
  390. {GL_GREEN, "GL_GREEN"},
  391. {GL_BLUE, "GL_BLUE"},
  392. {GL_ALPHA, "GL_ALPHA"},
  393. {GL_RGB, "GL_RGB"},
  394. {GL_RGBA, "GL_RGBA"},
  395. {GL_LUMINANCE, "GL_LUMINANCE"},
  396. {GL_LUMINANCE_ALPHA, "GL_LUMINANCE_ALPHA"},
  397. {GL_BITMAP, "GL_BITMAP"},
  398. {GL_POINT, "GL_POINT"},
  399. {GL_LINE, "GL_LINE"},
  400. {GL_FILL, "GL_FILL"},
  401. {GL_RENDER, "GL_RENDER"},
  402. {GL_FEEDBACK, "GL_FEEDBACK"},
  403. {GL_SELECT, "GL_SELECT"},
  404. {GL_FLAT, "GL_FLAT"},
  405. {GL_SMOOTH, "GL_SMOOTH"},
  406. {GL_KEEP, "GL_KEEP"},
  407. {GL_REPLACE, "GL_REPLACE"},
  408. {GL_INCR, "GL_INCR"},
  409. {GL_DECR, "GL_DECR"},
  410. {GL_VENDOR, "GL_VENDOR"},
  411. {GL_RENDERER, "GL_RENDERER"},
  412. {GL_VERSION, "GL_VERSION"},
  413. {GL_EXTENSIONS, "GL_EXTENSIONS"},
  414. {GL_S, "GL_S"},
  415. {GL_T, "GL_T"},
  416. {GL_R, "GL_R"},
  417. {GL_Q, "GL_Q"},
  418. {GL_MODULATE, "GL_MODULATE"},
  419. {GL_DECAL, "GL_DECAL"},
  420. {GL_TEXTURE_ENV_MODE, "GL_TEXTURE_ENV_MODE"},
  421. {GL_TEXTURE_ENV_COLOR, "GL_TEXTURE_ENV_COLOR"},
  422. {GL_TEXTURE_ENV, "GL_TEXTURE_ENV"},
  423. {GL_EYE_LINEAR, "GL_EYE_LINEAR"},
  424. {GL_OBJECT_LINEAR, "GL_OBJECT_LINEAR"},
  425. {GL_SPHERE_MAP, "GL_SPHERE_MAP"},
  426. {GL_TEXTURE_GEN_MODE, "GL_TEXTURE_GEN_MODE"},
  427. {GL_OBJECT_PLANE, "GL_OBJECT_PLANE"},
  428. {GL_EYE_PLANE, "GL_EYE_PLANE"},
  429. {GL_NEAREST, "GL_NEAREST"},
  430. {GL_LINEAR, "GL_LINEAR"},
  431. {GL_NEAREST_MIPMAP_NEAREST, "GL_NEAREST_MIPMAP_NEAREST"},
  432. {GL_LINEAR_MIPMAP_NEAREST, "GL_LINEAR_MIPMAP_NEAREST"},
  433. {GL_NEAREST_MIPMAP_LINEAR, "GL_NEAREST_MIPMAP_LINEAR"},
  434. {GL_LINEAR_MIPMAP_LINEAR, "GL_LINEAR_MIPMAP_LINEAR"},
  435. {GL_TEXTURE_MAG_FILTER, "GL_TEXTURE_MAG_FILTER"},
  436. {GL_TEXTURE_MIN_FILTER, "GL_TEXTURE_MIN_FILTER"},
  437. {GL_TEXTURE_WRAP_S, "GL_TEXTURE_WRAP_S"},
  438. {GL_TEXTURE_WRAP_T, "GL_TEXTURE_WRAP_T"},
  439. {GL_CLAMP, "GL_CLAMP"},
  440. {GL_REPEAT, "GL_REPEAT"},
  441. {GLU_SMOOTH, "GLU_SMOOTH"},
  442. {GLU_FLAT, "GLU_FLAT"},
  443. {GLU_NONE, "GLU_NONE"},
  444. {GLU_POINT, "GLU_POINT"},
  445. {GLU_LINE, "GLU_LINE"},
  446. {GLU_FILL, "GLU_FILL"},
  447. {GLU_SILHOUETTE, "GLU_SILHOUETTE"},
  448. {GLU_OUTSIDE, "GLU_OUTSIDE"},
  449. {GLU_INSIDE, "GLU_INSIDE"},
  450. {GLU_BEGIN, "GLU_BEGIN"},
  451. {GLU_VERTEX, "GLU_VERTEX"},
  452. {GLU_END, "GLU_END"},
  453. {GLU_ERROR, "GLU_ERROR"},
  454. {GLU_EDGE_FLAG, "GLU_EDGE_FLAG"},
  455. {GLU_CW, "GLU_CW"},
  456. {GLU_CCW, "GLU_CCW"},
  457. {GLU_INTERIOR, "GLU_INTERIOR"},
  458. {GLU_EXTERIOR, "GLU_EXTERIOR"},
  459. {GLU_UNKNOWN, "GLU_UNKNOWN"},
  460. {GLU_TESS_ERROR1, "GLU_TESS_ERROR1"},
  461. {GLU_TESS_ERROR2, "GLU_TESS_ERROR2"},
  462. {GLU_TESS_ERROR3, "GLU_TESS_ERROR3"},
  463. {GLU_TESS_ERROR4, "GLU_TESS_ERROR4"},
  464. {GLU_TESS_ERROR5, "GLU_TESS_ERROR5"},
  465. {GLU_TESS_ERROR6, "GLU_TESS_ERROR6"},
  466. {GLU_TESS_ERROR7, "GLU_TESS_ERROR7"},
  467. {GLU_TESS_ERROR8, "GLU_TESS_ERROR8"},
  468. { -1, "Bad enum" }
  469. };
  470.  
  471.  
  472. static int    nest = 0;
  473.  
  474. static void
  475. gl_indent()
  476. {
  477.     int i;
  478.  
  479.     for (i = 0; i < nest / 2; i++)
  480.     printf("\t");
  481.  
  482.     if (nest & 1)
  483.     printf("    ");
  484. }
  485.  
  486. static void
  487. gl_continue()
  488. {
  489.     printf("  ");
  490.     gl_indent();
  491. }
  492.  
  493. static void
  494. gl_header()
  495. {
  496.     if (output_code == -1) {
  497.     if (getenv("GLCODE") != NULL) {
  498.         output_code = 1;
  499.         printf("    float tVec[4];\n");
  500.         printf("    float tMat[16];\n");
  501.         nest = 1;
  502.     }
  503.     else output_code = 0;
  504.     }
  505.     if (!output_code)
  506.     if (recursing)
  507.         printf("     %d: ", recursing);
  508.     else
  509.         printf("OPENGL: ");
  510.     else
  511.     if (recursing)
  512.         printf("/* %d */ ", recursing);
  513.     gl_indent();
  514. }
  515.  
  516. /* Lookup enum, return a string for its name */
  517. static const char *
  518. gl_lookup_enum(Lookup *table, GLenum op)
  519. {
  520.     int i;
  521.  
  522.     /* Dumb, linear search for now: */
  523.     for (i = 0; table[i].enum_value != op &&
  524.      table[i].enum_value != -1; i++) {
  525.     /* do nothing-- keep on looping until found. */
  526.     }
  527.  
  528.     if (table[i].enum_value == -1) {
  529.     fprintf(stderr, "Error: bad gl enum value %d\n", op);
  530.     }
  531.     return table[i].enum_string;
  532. }
  533. /* Common case routine: */
  534. static const char *
  535. gl_enum(GLenum op)
  536. {
  537.     gl_lookup_enum(gl_constants, op);
  538. }
  539.  
  540. /* Define a vector-- used if we are outputting code */
  541. static void
  542. gl_defVec(const float *params, int nParams)
  543. {
  544.     if (output_code) {
  545.     int i;
  546.     for (i = 0; i < nParams; i++) {
  547.         printf("tVec[%d]=%g;", i, params[i]);
  548.     }
  549.     printf("\n");
  550.     gl_indent();
  551.     }
  552. }
  553. /* Return a string representing a vector */
  554. static const char *
  555. gl_printVec(const float *params, int nParams)
  556. {
  557.     static char buf[100];
  558.  
  559.     if (output_code) {
  560.     sprintf(buf, "tVec");
  561.     }
  562.     else {
  563.     int i;
  564.     char tbuf[20];
  565.     sprintf(buf, "[ ");
  566.     for (i = 0; i < nParams; i++) {
  567.         if (i < nParams - 1)
  568.         sprintf(tbuf, "%g, ", params[i]);
  569.         else
  570.         sprintf(tbuf, "%g", params[i]);
  571.         strcat(buf, tbuf);
  572.     }
  573.     sprintf(tbuf, "]");
  574.     strcat(buf, tbuf);
  575.     }
  576.     return buf;
  577. }
  578.  
  579. /* Same as above, but these use doubles */
  580. static void
  581. gl_defVecd(const double *params, int nParams)
  582. {
  583.     if (output_code) {
  584.     int i;
  585.     for (i = 0; i < nParams; i++) {
  586.         printf("tVec[%d]=%lg;", i, params[i]);
  587.     }
  588.     printf("\n");
  589.     gl_indent();
  590.     }
  591. }
  592. /* Return a string representing a vector */
  593. static const char *
  594. gl_printVecd(const double *params, int nParams)
  595. {
  596.     static char buf[100];
  597.  
  598.     if (output_code) {
  599.     sprintf(buf, "tVec");
  600.     }
  601.     else {
  602.     int i;
  603.     char tbuf[20];
  604.     sprintf(buf, "[ ");
  605.     for (i = 0; i < nParams; i++) {
  606.         if (i < nParams - 1)
  607.         sprintf(tbuf, "%lg, ", params[i]);
  608.         else
  609.         sprintf(tbuf, "%lg", params[i]);
  610.         strcat(buf, tbuf);
  611.     }
  612.     sprintf(tbuf, "]");
  613.     strcat(buf, tbuf);
  614.     }
  615.     return buf;
  616. }
  617.  
  618. static void
  619. gl_defMat(const GLfloat *m)
  620. {
  621.     if (!output_code) return;
  622.  
  623.     printf("  tMat[0] =%6.3f;tMat[1] =%6.3f;tMat[2] =%6.3f;tMat[3] =%6.3f;\n",
  624.        m[0], m[1], m[2], m[3]);
  625.     gl_continue();
  626.     printf("tMat[4] =%6.3f;tMat[5] =%6.3f;tMat[6] =%6.3f;tMat[7] =%6.3f;\n",
  627.        m[4], m[5], m[6], m[7]);
  628.     gl_continue();
  629.     printf("tMat[8] =%6.3f;tMat[9] =%6.3f;tMat[10]=%6.3f;tMat[11]=%6.3f;\n",
  630.        m[8], m[9], m[10], m[11]);
  631.     gl_continue();
  632.     printf("tMat[12]=%6.3f;tMat[13]=%6.3f;tMat[14]=%6.3f;tMat[15]=%6.3f;\n",
  633.        m[12], m[13], m[14], m[15]);
  634.     gl_indent();
  635. }
  636.  
  637. static void
  638. gl_printMat(const GLfloat *m)
  639. {
  640.     if (output_code) {
  641.     printf("tMat");
  642.     return;
  643.     }
  644.     printf("[%6.3f, %6.3f, %6.3f, %6.3f,\n",
  645.        m[ 0], m[ 1], m[ 2], m[ 3]);
  646.     gl_continue();
  647.     printf("               %6.3f, %6.3f, %6.3f, %6.3f,\n",
  648.        m[ 4], m[ 5], m[ 6], m[ 7]);
  649.     gl_continue();
  650.     printf("               %6.3f, %6.3f, %6.3f, %6.3f,\n",
  651.        m[ 8], m[ 9], m[10], m[11]);
  652.     gl_continue();
  653.     printf("               %6.3f, %6.3f, %6.3f, %6.3f]",
  654.        m[12], m[13], m[14], m[15]);
  655. }
  656.  
  657. void *
  658. lookup_sym(const char *symbol, const char *dsoName, void **dso)
  659. {
  660.     void *result;
  661.  
  662.     if (*dso == NULL) {
  663.     *dso = dlopen(dsoName, RTLD_LAZY);
  664.     if (*dso == NULL) {
  665.         fprintf(stderr, "Couldn't open %s\n", dsoName);
  666.     }
  667.     }
  668.     result = dlsym(*dso, symbol);
  669.     if (result == NULL) {
  670.     fprintf(stderr, "Couldn't find %s in %s\n", symbol, dsoName);
  671.     }
  672.     return result;
  673. }
  674.  
  675. #define QUOTE(foo) # foo
  676.  
  677. #define GL_GETSYM(returnType,name,argTypes) \
  678.     static returnType (*fn) argTypes = NULL; \
  679.     if (fn == NULL) \
  680.     fn = (returnType (*) argTypes )lookup_sym(QUOTE(name),gl,&gl_dso)
  681. #define GL_CALL(name, argTypes, argVals) \
  682.     { GL_GETSYM(void,name,argTypes); \
  683.     ++recursing; (*fn) argVals ; --recursing; }
  684. #define GL_RCALL(returnType, name, argTypes, argVals) \
  685.     { GL_GETSYM(returnType, name, argTypes); \
  686.     ++recursing; result = (*fn) argVals ; --recursing; }
  687.  
  688. void
  689. glAccum(GLenum op, GLfloat value)
  690. {
  691.  
  692.     gl_header();
  693.     printf("glAccum(%s, %g);\n", gl_enum(op), value);
  694.     GL_CALL(glAccum, (GLenum, GLfloat), (op, value));
  695. }
  696.  
  697. void
  698. glBegin(GLenum mode)
  699. {
  700.     static Lookup beginEnums[] = {
  701.     {GL_POINTS, "GL_POINTS"},
  702.     {GL_LINES, "GL_LINES"},
  703.     {GL_LINE_LOOP, "GL_LINE_LOOP"},
  704.     {GL_LINE_STRIP, "GL_LINE_STRIP"},
  705.     {GL_TRIANGLES, "GL_TRIANGLES"},
  706.     {GL_TRIANGLE_STRIP, "GL_TRIANGLE_STRIP"},
  707.     {GL_TRIANGLE_FAN, "GL_TRIANGLE_FAN"},
  708.     {GL_QUADS, "GL_QUADS"},
  709.     {GL_QUAD_STRIP, "GL_QUAD_STRIP"},
  710.     {GL_POLYGON, "GL_POLYGON"},
  711.     {-1, "Bad begin token"},
  712.     };
  713.  
  714.     gl_header();
  715.     printf("glBegin(%s);\n", gl_lookup_enum(beginEnums, mode));
  716.     nest++;
  717.     GL_CALL(glBegin, (GLenum), (mode));
  718. }
  719.  
  720. void
  721. glBitmap(GLsizei width, GLsizei height, GLfloat xorig,
  722.      GLfloat yorig,GLfloat xmove, GLfloat ymove,
  723.      const GLubyte *bitmap)
  724. {
  725.     gl_header();
  726.     printf("glBitmap(%d, %d, %g, %g, %g, %g, %#x);\n",
  727.        width, height, xorig, yorig, xmove, ymove, bitmap);
  728.     GL_CALL(glBitmap, \
  729.     (GLsizei,GLsizei,GLfloat,GLfloat,GLfloat,GLfloat,const GLubyte *), \
  730.     (width, height, xorig, yorig, xmove, ymove, bitmap));
  731. }
  732.  
  733. void
  734. glBlendFunc(GLenum sfactor, GLenum dfactor)
  735. {
  736.     gl_header();
  737.     printf("glBlendFunc(%s, %s);\n", gl_enum(sfactor), gl_enum(dfactor));
  738.     GL_CALL(glBlendFunc,(GLenum, GLenum), (sfactor, dfactor));
  739. }
  740.  
  741. void
  742. glCallList(GLuint list)
  743. {
  744.     gl_header();
  745.     printf("glCallList(%d);\n", list);
  746.     GL_CALL(glCallList,(GLuint),(list));
  747. }
  748.  
  749. void
  750. glCallLists(GLsizei n, GLenum type, const GLvoid *lists)
  751. {
  752.     gl_header();
  753.     printf("glCallLists(%d, %s, \"%s\");\n", n, gl_enum(type),
  754.        (const char *)lists);
  755.     GL_CALL(glCallLists,(GLsizei, GLenum, const GLvoid *), \
  756.          (n, type, lists));
  757. }
  758.  
  759. void
  760. glClear(GLbitfield mask)
  761. {
  762.     gl_header();
  763.     printf("glClear(%#x);\n", mask);
  764.     GL_CALL(glClear,(GLbitfield),(mask));
  765. }
  766.  
  767. void
  768. glClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
  769. {
  770.     gl_header();
  771.     printf("glClearColor(%g, %g, %g, %g);\n", r, g, b, a);
  772.     GL_CALL(glClearColor,(GLfloat, GLfloat, GLfloat, GLfloat), (r,g,b,a));
  773. }
  774.  
  775. void
  776. glClearIndex(GLfloat i)
  777. {
  778.     gl_header();
  779.     printf("glClearIndex(%g);\n", i);
  780.     GL_CALL(glClearIndex,(GLfloat), (i));
  781. }
  782.  
  783. void
  784. glClipPlane(GLenum plane, const GLdouble *equation)
  785. {
  786.     gl_header();
  787.     gl_defVecd(equation, 4);
  788.     printf("glClipPlane(%s, %s);\n",
  789.        gl_enum(plane), gl_printVecd(equation, 4));
  790.     GL_CALL(glClipPlane,(GLenum, const GLdouble *), (plane, equation));
  791. }
  792.  
  793. void
  794. glColor3f(GLfloat red, GLfloat green, GLfloat blue)
  795. {
  796.     gl_header();
  797.     printf("glColor3f(%g, %g, %g);\n", red, green, blue);
  798.     GL_CALL(glColor3f,(GLfloat, GLfloat, GLfloat), (red, green, blue));
  799. }
  800.  
  801. void
  802. glColor3fv(const GLfloat *v)
  803. {
  804. #ifdef VEC_ROUTINES
  805.     gl_header();
  806.     gl_defVec(v, 3);
  807.     printf("glColor3fv(%s);\n", gl_printVec(v, 3));
  808.  
  809.     GL_CALL(glColor3fv, (const GLfloat *), (v));
  810. #else
  811.     glColor3f(v[0], v[1], v[2]);
  812. #endif
  813. }
  814.  
  815. void
  816. glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
  817. {
  818.     gl_header();
  819.     printf("glColor4f(%g, %g, %g, %g);\n", red, green, blue, alpha);
  820.     GL_CALL(glColor4f, (GLfloat,GLfloat,GLfloat,GLfloat), (red,green,blue,alpha));
  821. }
  822.  
  823. void
  824. glColor4fv(const GLfloat *v)
  825. {
  826. #ifdef VEC_ROUTINES
  827.     gl_header();
  828.     gl_defVec(v, 4);
  829.     printf("glColor4fv(%s);\n", gl_printVec(v, 4));
  830.     GL_CALL(glColor4fv, (const GLfloat *), (v));
  831. #else
  832.     glColor4f(v[0], v[1], v[2], v[3]);
  833. #endif
  834. }
  835.  
  836. void
  837. glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
  838. {
  839.     gl_header();
  840.     printf("glColor4ub(%d, %d, %d, %d);\n",
  841.        (int) red, (int) green, (int) blue, (int) alpha);
  842.     GL_CALL(glColor4ub, (GLubyte,GLubyte,GLubyte,GLubyte), (red,green,blue,alpha));
  843. }
  844.  
  845. void
  846. glColorMaterial(GLenum face, GLenum mode)
  847. {
  848.     gl_header();
  849.     printf("glColorMaterial(%s, %s);\n", gl_enum(face), gl_enum(mode));
  850.     GL_CALL(glColorMaterial, (GLenum,GLenum), (face,mode));
  851. }
  852.  
  853. void
  854. glCullFace(GLenum mode)
  855. {
  856.     gl_header();
  857.     printf("glCullFace(%s);\n", gl_enum(mode));
  858.     GL_CALL(glCullFace, (GLenum), (mode));
  859. }
  860.  
  861. void
  862. glDeleteLists(GLuint list, GLsizei range)
  863. {
  864.     gl_header();
  865.     printf("glDeleteLists(%d, %d);\n", list, range);
  866.     GL_CALL(glDeleteLists, (GLuint, GLsizei), (list,range));
  867. }
  868.  
  869. void
  870. glDepthFunc(GLenum func)
  871. {
  872.     gl_header();
  873.     printf("glDepthFunc(%s);\n", gl_enum(func));
  874.     GL_CALL(glDepthFunc, (GLenum), (func));
  875. }
  876.  
  877. void
  878. glDepthMask(GLboolean flag)
  879. {
  880.     gl_header();
  881.     printf("glDepthMask(%d);\n", flag);
  882.     GL_CALL(glDepthMask, (GLboolean), (flag));
  883. }
  884.  
  885. void
  886. glDisable(GLenum cap)
  887. {
  888.     gl_header();
  889.     printf("glDisable(%s);\n", gl_enum(cap));
  890.     GL_CALL(glDisable, (GLenum), (cap));
  891. }
  892.  
  893. void
  894. glDrawBuffer(GLenum mode)
  895. {
  896.     gl_header();
  897.     printf("glDrawBuffer(%s);\n", gl_enum(mode));
  898.     GL_CALL(glDrawBuffer, (GLenum), (mode));
  899. }
  900.  
  901. void
  902. glEnable(GLenum cap)
  903. {
  904.     gl_header();
  905.     printf("glEnable(%s);\n", gl_enum(cap));
  906.     GL_CALL(glEnable, (GLenum), (cap));
  907. }
  908.  
  909. void
  910. glEnd(void)
  911. {
  912.     nest--;
  913.     gl_header();
  914.     printf("glEnd();\n");
  915.     GL_CALL(glEnd, (), ());
  916. }
  917.  
  918. void
  919. glEndList(void)
  920. {
  921.     nest--;
  922.     gl_header();
  923.     printf("glEndList();\n");
  924.     GL_CALL(glEndList, (), ());
  925. }
  926.  
  927. void
  928. glFlush()
  929. {
  930.     gl_header();
  931.     printf("glFlush();\n");
  932.     GL_CALL(glFlush, (), ());
  933. }
  934.  
  935. void
  936. glFogf(GLenum pname, GLfloat param)
  937. {
  938.     gl_header();
  939.     printf("glFogf(%s, %g);\n", gl_enum(pname), param);
  940.     GL_CALL(glFogf, (GLenum,GLfloat), (pname,param));
  941. }
  942.  
  943. void
  944. glFogfv(GLenum pname, const GLfloat *params)
  945. {
  946.     gl_header();
  947.     gl_defVec(params, 3);
  948.     printf("glFogfv(%s, %s);\n",
  949.        gl_enum(pname), gl_printVec(params, 3));
  950.     GL_CALL(glFogfv, (GLenum,const GLfloat *), (pname, params));
  951. }
  952.  
  953. void
  954. glFrontFace(GLenum mode)
  955. {
  956.     gl_header();
  957.     printf("glFrontFace(%s);\n", gl_enum(mode));
  958.     GL_CALL(glFrontFace, (GLenum), (mode));
  959. }
  960.  
  961. GLuint
  962. glGenLists(GLsizei range)
  963. {
  964.     int    result;
  965.  
  966.     gl_header();
  967.     printf("glGenLists(%d);\n", range);
  968.     GL_RCALL(GLuint,glGenLists,(GLsizei),(range));
  969.     printf(" /* glGenLists returned %d */\n", result);
  970.     return result;
  971. }
  972.  
  973. void
  974. glGetBooleanv(GLenum pname, GLboolean *params)
  975. {
  976.     gl_header();
  977.     if (output_code) printf("/* ");
  978.     printf("glGetBooleanv(%s, ...);", gl_enum(pname));
  979.     if (output_code) printf(" */");
  980.     printf("\n");
  981.     GL_CALL(glGetBooleanv, (GLenum, GLboolean *), (pname,params));
  982. }
  983.  
  984. GLenum
  985. glGetError()
  986. {
  987.     GLenum result;
  988.  
  989.     gl_header();
  990.     printf("glGetError();\n");
  991.     GL_RCALL(GLenum,glGetError,(),());
  992.     printf("/* glGetError returned %d */\n", result);
  993.     return result;
  994. }
  995.  
  996. void
  997. glGetFloatv(GLenum pname, GLfloat *params)
  998. {
  999.     gl_header();
  1000.     if (output_code) printf("/* ");
  1001.     printf("glGetFloatv(%s, ...);", gl_enum(pname));
  1002.     if (output_code) printf("*/");
  1003.     printf("\n");
  1004.     GL_CALL(glGetFloatv, (GLenum,GLfloat *), (pname,params));
  1005. }
  1006.  
  1007. void
  1008. glGetIntegerv(GLenum pname, GLint *params)
  1009. {
  1010.     gl_header();
  1011.     if (output_code) printf("/* ");
  1012.     printf("glGetIntegerv(%s, ...);", gl_enum(pname));
  1013.     if (output_code) printf("*/");
  1014.     printf("\n");
  1015.  
  1016.     /* Special case for values Inventor relies upon */
  1017.     if (pname == GL_MAX_LIGHTS)
  1018.     *params = 8;
  1019.     GL_CALL(glGetIntegerv, (GLenum,GLint *), (pname,params));
  1020. }
  1021.  
  1022. void
  1023. glIndexi(GLint c)
  1024. {
  1025.     gl_header();
  1026.     printf("glIndexi(%d);\n", c);
  1027.     GL_CALL(glIndexi, (GLint), (c));
  1028. }
  1029.  
  1030. void
  1031. glLightModelfv(GLenum pname, const GLfloat *params)
  1032. {
  1033.     gl_header();
  1034.     gl_defVec(params, 4);
  1035.     GL_CALL(glLightModelfv, (GLenum,const GLfloat *), (pname,params));
  1036.     printf("glLightModelfv(%s, %s);\n", gl_enum(pname),
  1037.        gl_printVec(params, 4));
  1038. }
  1039.  
  1040. void
  1041. glLightModeli(GLenum pname, GLint param)
  1042. {
  1043.     gl_header();
  1044.     printf("glLightModeli(%s, %d);\n", gl_enum(pname), param);
  1045.     GL_CALL(glLightModeli, (GLenum, GLint), (pname, param));
  1046. }
  1047.  
  1048. void
  1049. glLightf(GLenum light, GLenum pname, GLfloat param)
  1050. {
  1051.     gl_header();
  1052.     printf("glLightf(%s, %s, %g);\n", gl_enum(light), gl_enum(pname), param);
  1053.     GL_CALL(glLightf, (GLenum,GLenum,GLfloat), (light,pname,param));
  1054. }
  1055.  
  1056. void
  1057. glLightfv(GLenum light, GLenum pname, const GLfloat *params)
  1058. {
  1059.     gl_header();
  1060.     if (pname == GL_SPOT_DIRECTION) {
  1061.     gl_defVec(params, 3);
  1062.     printf("glLightfv(%s, %s, %s);\n",
  1063.            gl_enum(light), gl_enum(pname),
  1064.            gl_printVec(params, 3));
  1065.     GL_CALL(glLightfv, (GLenum,GLenum,const GLfloat *), (light,pname,params));
  1066.     }
  1067.     else {
  1068.     gl_defVec(params, 4);
  1069.     printf("glLightfv(%s, %s, %s);\n",
  1070.            gl_enum(light), gl_enum(pname),
  1071.            gl_printVec(params, 4));
  1072.     }
  1073. }
  1074.  
  1075. void
  1076. glLineStipple(GLint factor, GLushort pattern)
  1077. {
  1078.     gl_header();
  1079.     printf("glLineStipple(%d, %#hx);\n", factor, pattern);
  1080.     GL_CALL(glLineStipple, (GLint,GLushort), (factor,pattern));
  1081. }
  1082.  
  1083. void
  1084. glLineWidth(GLfloat width)
  1085. {
  1086.     gl_header();
  1087.     printf("glLineWidth(%g);\n", width);
  1088.     GL_CALL(glLineWidth, (GLfloat), (width));
  1089. }
  1090.  
  1091. void
  1092. glListBase(GLuint base)
  1093. {
  1094.     gl_header();
  1095.     printf("glListBase(%d);\n", base);
  1096.     GL_CALL(glListBase, (GLuint), (base));
  1097. }
  1098.  
  1099. void
  1100. glLoadIdentity()
  1101. {
  1102.     gl_header();
  1103.     printf("glLoadIdentity();\n");
  1104.     GL_CALL(glLoadIdentity, (), ());
  1105. }
  1106.  
  1107. void
  1108. glLoadMatrixf(const GLfloat *m)
  1109. {
  1110.     gl_header();
  1111.     gl_defMat(m);
  1112.     printf("glLoadMatrixf(");
  1113.     gl_printMat(m);
  1114.     printf(");\n");
  1115.  
  1116.     GL_CALL(glLoadMatrixf, (const GLfloat *), (m));
  1117. }
  1118.  
  1119. void
  1120. glMaterialf(GLenum face, GLenum pname, GLfloat param)
  1121. {
  1122.     gl_header();
  1123.     printf("glMaterialf(%s, %s, %g);\n", gl_enum(face), gl_enum(pname), param);
  1124.     GL_CALL(glMaterialf, (GLenum,GLenum,GLfloat), (face,pname,param));
  1125. }
  1126.  
  1127. void
  1128. glMaterialfv(GLenum face, GLenum pname, const GLfloat *params)
  1129. {
  1130.     gl_header();
  1131.  
  1132.     if (pname == GL_SHININESS)
  1133.     printf("glMaterialfv(%s, %s, [ %g ]);\n",
  1134.            gl_enum(face), gl_enum(pname), *params);
  1135.  
  1136.     else if (pname == GL_COLOR_INDEXES) {
  1137.     gl_defVec(params, 3);
  1138.     printf("glMaterialfv(%s, %s, %s);\n",
  1139.            gl_enum(face), gl_enum(pname), gl_printVec(params, 3));
  1140.     GL_CALL(glMaterialfv, (GLenum,GLenum,const GLfloat *), (face,pname,params));
  1141.     }
  1142.  
  1143.     else {
  1144.     gl_defVec(params, 4);
  1145.     printf("glMaterialfv(%s, %s, %s);\n",
  1146.            gl_enum(face), gl_enum(pname), gl_printVec(params, 4));
  1147.     }
  1148. }
  1149.  
  1150. void
  1151. glMatrixMode(GLenum mode)
  1152. {
  1153.     gl_header();
  1154.     printf("glMatrixMode(%s);\n", gl_enum(mode));
  1155.     GL_CALL(glMatrixMode, (GLenum), (mode));
  1156. }
  1157.  
  1158. void
  1159. glMultMatrixf(const GLfloat *m)
  1160. {
  1161.     gl_header();
  1162.     printf("glMultMatrixf([%6.3f, %6.3f, %6.3f, %6.3f,\n",
  1163.        m[ 0], m[ 1], m[ 2], m[ 3]);
  1164.     gl_continue();
  1165.     printf("               %6.3f, %6.3f, %6.3f, %6.3f,\n",
  1166.        m[ 4], m[ 5], m[ 6], m[ 7]);
  1167.     gl_continue();
  1168.     printf("               %6.3f, %6.3f, %6.3f, %6.3f,\n",
  1169.        m[ 8], m[ 9], m[10], m[11]);
  1170.     gl_continue();
  1171.     printf("               %6.3f, %6.3f, %6.3f, %6.3f]);\n",
  1172.        m[12], m[13], m[14], m[15]);
  1173.     GL_CALL(glMultMatrixf, (const GLfloat *), (m));
  1174. }
  1175.  
  1176. void
  1177. glNewList(GLuint list, GLenum mode)
  1178. {
  1179.     gl_header();
  1180.     printf("glNewList(%d, %s);\n", list, gl_enum(mode));
  1181.     nest++;
  1182.     GL_CALL(glNewList, (GLuint,GLenum), (list,mode));
  1183. }
  1184.  
  1185. void
  1186. glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
  1187. {
  1188.     gl_header();
  1189.     printf("glNormal3f(%g, %g, %g);\n", nx, ny, nz);
  1190.     GL_CALL(glNormal3f, (GLfloat,GLfloat,GLfloat), (nx,ny,nz));
  1191. }
  1192.  
  1193. void
  1194. glNormal3fv(const GLfloat *v)
  1195. {
  1196. #ifdef VEC_ROUTINES
  1197.     gl_header();
  1198.     gl_defVec(v, 3);
  1199.     printf("glNormal3fv(%s);\n", gl_printVec(v, 3));
  1200.     GL_CALL(glNormal3fv, (const GLfloat *), (v));
  1201. #else
  1202.     glNormal3f(v[0], v[1], v[2]);
  1203. #endif
  1204. }
  1205.  
  1206. void
  1207. glOrtho(GLdouble left, GLdouble right,GLdouble bottom, GLdouble
  1208.     top,GLdouble near, GLdouble far)
  1209. {
  1210.     gl_header();
  1211.     printf("glOrtho(%lg, %lg, %lg, %lg, %lg, %lg);\n",
  1212.        left, right, bottom, top, near, far);
  1213.     GL_CALL(glOrtho, \
  1214.          (GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble), \
  1215.          (left, right, bottom, top, near, far));
  1216. }
  1217.  
  1218. void
  1219. glPixelStorei(GLenum pname, GLint param)
  1220. {
  1221.     gl_header();
  1222.     printf("glPixelStorei(%s, %d);\n", gl_enum(pname), param);
  1223.     GL_CALL(glPixelStorei, (GLenum, GLint), (pname, param));
  1224. }
  1225.  
  1226. void
  1227. glPixelTransferf(GLenum pname, GLfloat param)
  1228. {
  1229.     gl_header();
  1230.     printf("glPixelTransferf(%s, %f);\n", gl_enum(pname), param);
  1231.     GL_CALL(glPixelTransferf, (GLenum, GLfloat), (pname,param));
  1232. }
  1233.  
  1234. void
  1235. glPointSize(GLfloat size)
  1236. {
  1237.     gl_header();
  1238.     printf("glPointSize(%g);\n", size);
  1239.     GL_CALL(glPointSize, (GLfloat), (size));
  1240. }
  1241.  
  1242. void
  1243. glPolygonMode(GLenum face, GLenum mode)
  1244. {
  1245.     gl_header();
  1246.     printf("glPolygonMode(%s, %s);\n", gl_enum(face), gl_enum(mode));
  1247.     GL_CALL(glPolygonMode, (GLenum, GLenum), (face,mode));
  1248. }
  1249.  
  1250. static char *
  1251. getStipBuf(const unsigned long *l)
  1252. {
  1253.     int            i;
  1254.     static        char buf[33];
  1255.  
  1256.     for (i = 0; i < 32; i++)
  1257.     buf[i] = (*l & (1 << (31 - i)) ? '#' : '.');
  1258.  
  1259.     buf[32] = '\0';
  1260.  
  1261.     return buf;
  1262. }
  1263.  
  1264. void
  1265. glPolygonStipple(const GLubyte *mask)
  1266. {
  1267.     int            i;
  1268.     const unsigned long    *ul;
  1269.  
  1270.     gl_header();
  1271.     ul = (const unsigned long *) mask;
  1272.     printf("glPolygonStipple(0x%.8lx, /* %s */\n", *ul, getStipBuf(ul));
  1273.  
  1274.     for (i = 1; i < 31; i++) {
  1275.     gl_continue();
  1276.     ul = (const unsigned long *) (mask + 4 * i);
  1277.     printf("                       0x%.8lx, /* %s */\n",
  1278.            *ul, getStipBuf(ul));
  1279.     }
  1280.  
  1281.     gl_continue();
  1282.     ul = (const unsigned long *) (mask + 4 * 31);
  1283.     printf("                       0x%.8lx); /* %s */\n", *ul, getStipBuf(ul));
  1284.  
  1285.     GL_CALL(glPolygonStipple, (const GLubyte *), (mask));
  1286. }
  1287.     
  1288. void
  1289. glPopAttrib(void)
  1290. {
  1291.     nest--;
  1292.     gl_header();
  1293.     printf("glPopAttrib();\n");
  1294.     GL_CALL(glPopAttrib, (), ());
  1295. }
  1296.  
  1297. void
  1298. glPopMatrix(void)
  1299. {
  1300.     nest--;
  1301.     gl_header();
  1302.     printf("glPopMatrix();\n");
  1303.     GL_CALL(glPopMatrix, (), ());
  1304. }
  1305.  
  1306. void
  1307. glPushAttrib(GLbitfield mask)
  1308. {
  1309.     gl_header();
  1310.     printf("glPushAttrib(%#x);\n", mask);
  1311.     nest++;
  1312.     GL_CALL(glPushAttrib, (GLbitfield), (mask));
  1313. }
  1314.  
  1315. void
  1316. glPushMatrix(void)
  1317. {
  1318.     gl_header();
  1319.     printf("glPushMatrix();\n");
  1320.     nest++;
  1321.     GL_CALL(glPushMatrix, (), ());
  1322. }
  1323.  
  1324. void
  1325. glRasterPos3fv(const GLfloat *v)
  1326. {
  1327.     gl_header();
  1328.     gl_defVec(v, 3);
  1329.     printf("glRasterPos3fv(%s);\n", gl_printVec(v, 3));
  1330.     GL_CALL(glRasterPos3fv, (const GLfloat *), (v));
  1331. }
  1332.  
  1333. void
  1334. glReadBuffer (GLenum mode)
  1335. {
  1336.     gl_header();
  1337.     printf("glReadBuffer(%d);\n", gl_enum(mode));
  1338.     GL_CALL(glReadBuffer, (GLenum), (mode));
  1339. }
  1340.  
  1341. void
  1342. glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,GLenum
  1343.          format, GLenum type, GLvoid *pixels)
  1344. {
  1345.     gl_header();
  1346.     printf("glReadPixels(%d, %d, %d, %d, %s, %s, %#x);\n",
  1347.        x, y, width, height, gl_enum(format), gl_enum(type), pixels);
  1348.  
  1349.     GL_CALL(glReadPixels, \
  1350.     (GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,GLvoid *), \
  1351.     (x,y,width,height,format,type,pixels)); 
  1352. }
  1353.  
  1354. void
  1355. glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2)
  1356. {
  1357.     gl_header();
  1358.     printf("glRects(%hd, %hd, %hd, %hd);\n", x1, y1, x2, y2);
  1359.  
  1360.     GL_CALL(glRects, (GLshort,GLshort,GLshort,GLshort), \
  1361.          (x1,y1,x2,y2));
  1362. }
  1363.  
  1364. void
  1365. glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
  1366. {
  1367.     gl_header();
  1368.     printf("glRotatef(%g, %g, %g, %g);\n", angle, x, y, z);
  1369.  
  1370.     GL_CALL(glRotatef, (GLfloat,GLfloat,GLfloat,GLfloat), \
  1371.          (angle, x, y, z));
  1372. }
  1373.  
  1374. void
  1375. glScalef(GLfloat x, GLfloat y, GLfloat z)
  1376. {
  1377.     gl_header();
  1378.     printf("glScalef(%g, %g, %g);\n", x, y, z);
  1379.     GL_CALL(glScalef, (GLfloat,GLfloat,GLfloat), (x,y,z));
  1380. }
  1381.  
  1382. void
  1383. glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
  1384. {
  1385.     gl_header();
  1386.     printf("glScissor(%d, %d, %d, %d);\n", x, y, width, height);
  1387.  
  1388.     GL_CALL(glScissor, (GLint,GLint,GLsizei,GLsizei), \
  1389.          (x,y,width,height));
  1390. }
  1391.  
  1392. void
  1393. glShadeModel(GLenum mode)
  1394. {
  1395.     gl_header();
  1396.     printf("glShadeModel(%s);\n", gl_enum(mode));
  1397.     GL_CALL(glShadeModel, (GLenum), (mode));
  1398. }
  1399.  
  1400. void
  1401. glTexCoord2f(GLfloat s, GLfloat t)
  1402. {
  1403.     gl_header();
  1404.     printf("glTexCoord2f(%g, %g);\n", s, t);
  1405.     GL_CALL(glTexCoord2f, (GLfloat,GLfloat), (s,t));
  1406. }
  1407.  
  1408. void
  1409. glTexCoord2fv(const GLfloat *v)
  1410. {
  1411. #ifdef VEC_ROUTINES
  1412.     gl_header();
  1413.     gl_defVec(v, 2);
  1414.     printf("glTexCoord2fv(%s);\n", gl_printVec(v, 2));
  1415.     GL_CALL(glTexCoord2fv, (const GLfloat *), (v));
  1416. #else
  1417.     glTexCoord2f(v[0], v[1]);
  1418. #endif
  1419. }
  1420.  
  1421. void
  1422. glTexCoord4fv(const GLfloat *v)
  1423. {
  1424.     gl_header();
  1425.     gl_defVec(v, 4);
  1426.     printf("glTexCoord4fv(%s);\n", gl_printVec(v, 4));
  1427.     GL_CALL(glTexCoord4fv, (const GLfloat *), (v));
  1428. }
  1429.  
  1430. void
  1431. glTexEnvfv(GLenum target, GLenum pname, const GLfloat *param)
  1432. {
  1433.     gl_header();
  1434.     gl_defVec(param, 4);
  1435.     printf("glTexEnvfv(%s, %s, %s);\n", gl_enum(target),
  1436.        gl_enum(pname), gl_printVec(param, 4));
  1437.     GL_CALL(glTexEnvfv, (GLenum,GLenum,const GLfloat *),\
  1438.          (target, pname, param));
  1439. }
  1440.  
  1441. void
  1442. glTexEnvi(GLenum target, GLenum pname, GLint param)
  1443. {
  1444.  
  1445.     gl_header();
  1446.     printf("glTexEnvi(%s, %s, %s);\n", gl_enum(target), gl_enum(pname),
  1447.        gl_enum(param));
  1448.     GL_CALL(glTexEnvi, (GLenum,GLenum,GLint), (target,pname,param));
  1449. }
  1450.  
  1451. void
  1452. glTexGenf(GLenum coord, GLenum pname, GLfloat param)
  1453. {
  1454.     gl_header();
  1455.     printf("glTexGenf(%s, %s, %g);\n", gl_enum(coord), gl_enum(pname), param);
  1456.     GL_CALL(glTexGenf, (GLenum,GLenum,GLfloat), (coord,pname,param));
  1457. }
  1458.  
  1459. void
  1460. glTexGeni(GLenum coord, GLenum pname, GLint param)
  1461. {
  1462.     gl_header();
  1463.     printf("glTexGeni(%s, %s, %d);\n", gl_enum(coord), gl_enum(pname), param);
  1464.     GL_CALL(glTexGeni, (GLenum,GLenum,GLint), (coord,pname,param));
  1465. }
  1466.  
  1467. void
  1468. glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
  1469. {
  1470.     gl_header();
  1471.     gl_defVec(params, 4);
  1472.     printf("glTexGenfv(%s, %s, %s);\n", gl_enum(coord),
  1473.        gl_enum(pname), gl_printVec(params, 4));
  1474.     GL_CALL(glTexGenfv, (GLenum,GLenum,const GLfloat *), \
  1475.          (coord,pname,params));
  1476. }
  1477.  
  1478. void
  1479. glTexParameteri(GLenum target, GLenum pname, GLint param)
  1480. {
  1481.     gl_header();
  1482.     printf("glTexParameteri(%s, %s, %s);\n", gl_enum(target),
  1483.        gl_enum(pname),
  1484.        gl_enum(param));
  1485.     GL_CALL(glTexParameteri, (GLenum,GLenum,GLint), \
  1486.          (target,pname,param));
  1487. }
  1488.  
  1489. void
  1490. glTranslatef(GLfloat x, GLfloat y, GLfloat z)
  1491. {
  1492.     gl_header();
  1493.     printf("glTranslatef(%g, %g, %g);\n", x, y, z);
  1494.     GL_CALL(glTranslatef, (GLfloat,GLfloat,GLfloat), (x,y,z));
  1495. }
  1496.  
  1497. void
  1498. glVertex2f(GLfloat x, GLfloat y)
  1499. {
  1500.     gl_header();
  1501.     printf("glVertex2f(%g, %g);\n", x, y);
  1502.     GL_CALL(glVertex2f, (GLfloat,GLfloat), (x,y));
  1503. }
  1504.  
  1505. void
  1506. glVertex2fv(const GLfloat *v)
  1507. {
  1508. #ifdef VEC_ROUTINES
  1509.     gl_header();
  1510.     gl_defVec(v, 2);
  1511.     printf("glVertex2fv(%s);\n", gl_printVec(v, 2));
  1512.     GL_CALL(glVertex2fv, (const GLfloat *), (v));
  1513. #else
  1514.     glVertex2f(v[0], v[1]);
  1515. #endif
  1516. }
  1517.  
  1518. void
  1519. glVertex3f(GLfloat x, GLfloat y, GLfloat z)
  1520. {
  1521.     gl_header();
  1522.     printf("glVertex3f(%g, %g, %g);\n", x, y, z);
  1523.     GL_CALL(glVertex3f, (GLfloat,GLfloat,GLfloat), (x,y,z));
  1524. }
  1525.  
  1526. void
  1527. glVertex3fv(const GLfloat *v)
  1528. {
  1529. #ifdef VEC_ROUTINES
  1530.     gl_header();
  1531.     gl_defVec(v, 3);
  1532.     printf("glVertex3fv(%s);\n", gl_printVec(v, 3));
  1533.     GL_CALL(glVertex2fv, (const GLfloat *), (v));
  1534. #else
  1535.     glVertex3f(v[0], v[1], v[2]);
  1536. #endif
  1537. }
  1538.  
  1539. void
  1540. glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
  1541. {
  1542.     gl_header();
  1543.     printf("glVertex4f(%g, %g, %g, %g);\n", x, y, z, w);
  1544.     GL_CALL(glVertex4f, (GLfloat,GLfloat,GLfloat,GLfloat), (x,y,z,w));
  1545. }
  1546.  
  1547. void
  1548. glVertex4fv(const GLfloat *v)
  1549. {
  1550. #ifdef VEC_ROUTINES
  1551.     gl_header();
  1552.     gl_defVec(v, 4);
  1553.     printf("glVertex4fv(%s);\n", gl_printVec(v, 4));
  1554.     GL_CALL(glVertex2fv, (const GLfloat *), (v));
  1555. #else
  1556.     glVertex4f(v[0], v[1], v[2], v[3]);
  1557. #endif
  1558. }
  1559.  
  1560. void
  1561. glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
  1562. {
  1563.     gl_header();
  1564.     printf("glViewport(%d, %d, %d, %d);\n", x, y, width, height);
  1565.     GL_CALL(glViewport, (GLint,GLint,GLsizei,GLsizei),\
  1566.          (x,y,width,height));
  1567. }
  1568.  
  1569. /******************************************************************/
  1570.  
  1571. #define GLU_GETSYM(returnType,name,argTypes) \
  1572.     static returnType (*fn) argTypes = NULL; \
  1573.     if (fn == NULL) \
  1574.     fn = (returnType (*) argTypes )lookup_sym(QUOTE(name),glu,&glu_dso )
  1575. #define GLU_CALL(name, argTypes, argVals) \
  1576.     { GLU_GETSYM(void,name,argTypes); \
  1577.     ++recursing; (*fn) argVals ; --recursing; }
  1578. #define GLU_RCALL(returnType, name, argTypes, argVals) \
  1579.     { GLU_GETSYM(returnType, name, argTypes); \
  1580.     ++recursing; result = (*fn) argVals ; --recursing; }
  1581.  
  1582. void
  1583. gluBeginPolygon(GLUtriangulatorObj *tobj)
  1584. {
  1585.     printf("gluBeginPolygon(%#x);\n", tobj);
  1586.     GLU_CALL(gluBeginPolygon, (GLUtriangulatorObj *),(tobj));
  1587. }
  1588.  
  1589. void
  1590. gluBeginSurface(GLUnurbsObj *nobj)
  1591. {
  1592.     gl_header();
  1593.     printf("gluBeginSurface(%#x);\n", nobj);
  1594.     GLU_CALL(gluBeginSurface, (GLUnurbsObj *),(nobj));
  1595. }
  1596.  
  1597. void
  1598. gluBeginTrim(GLUnurbsObj *nobj)
  1599. {
  1600.     gl_header();
  1601.     printf("gluBeginTrim(%#x);\n", nobj);
  1602.     GLU_CALL(gluBeginTrim, (GLUnurbsObj *),(nobj));
  1603. }
  1604.  
  1605. int
  1606. gluBuild2DMipmaps(GLenum target, GLint components,
  1607.           GLint width, GLint height,
  1608.           GLenum format, GLenum type, const void *data)
  1609. {
  1610.     int result;
  1611.  
  1612.     gl_header();
  1613.     if (!output_code) {
  1614.     printf("gluBuild2DMipmaps(%s, %d, %d, %d, %s, %s, %#x);\n",
  1615.            gl_enum(target), components, width, height,
  1616.            gl_enum(format), gl_enum(type), data);
  1617.     }
  1618.     else {
  1619. #ifndef SHORT
  1620.     int i;
  1621.     printf("{\n");
  1622.     gl_continue();
  1623.     printf("unsigned char b[%d];", width*height*components);
  1624.     for (i = 0; i < width*height*components; i++) {
  1625.         printf("b[%d]=%#x;", i, ((unsigned char *)data)[i]);
  1626.     }
  1627.     printf("\n");
  1628.     gl_continue();
  1629. #endif
  1630.     printf("gluBuild2DMipmaps(%s, %d, %d, %d, %s, %s, ....);\n",
  1631.            gl_enum(target), components, width, height,
  1632.            gl_enum(format), gl_enum(type));
  1633. #ifndef SHORT
  1634.     printf("}\n");
  1635. #endif
  1636.     }
  1637.     GLU_RCALL(int,gluBuild2DMipmaps, \
  1638.     (GLenum, GLint,GLint,GLint,GLenum,GLenum,const void *),\
  1639.            (target, components, width, height, format, type,data));
  1640.     printf("/* gluBuild2DMipMaps returned %d */\n", result);
  1641.     return result;
  1642. }
  1643.  
  1644. void
  1645. gluDeleteNurbsRenderer(GLUnurbsObj *nobj)
  1646. {
  1647.     gl_header();
  1648.     printf("gluDeleteNurbsRenderer(%#x);\n", nobj);
  1649.     GLU_CALL(gluDeleteNurbsRenderer, (GLUnurbsObj *),(nobj));
  1650. }
  1651.  
  1652. void
  1653. gluDeleteTess(GLUtriangulatorObj *tobj)
  1654. {
  1655.     gl_header();
  1656.     printf("gluDeleteTess(%#x);\n", tobj);
  1657.     GLU_CALL(gluDeleteTess, (GLUtriangulatorObj *),(tobj));
  1658. }
  1659.  
  1660. void
  1661. gluEndPolygon(GLUtriangulatorObj *tobj)
  1662. {
  1663.     gl_header();
  1664.     printf("gluEndPolygon(%#x);\n", tobj);
  1665.     GLU_CALL(gluEndPolygon, (GLUtriangulatorObj *),(tobj));
  1666. }
  1667.  
  1668. void
  1669. gluEndSurface(GLUnurbsObj *nobj)
  1670. {
  1671.     gl_header();
  1672.     printf("gluEndSurface(%#x);\n", nobj);
  1673.     GLU_CALL(gluEndSurface, (GLUnurbsObj *),(nobj));
  1674. }
  1675.  
  1676. void
  1677. gluEndTrim(GLUnurbsObj *nobj)
  1678. {
  1679.     gl_header();
  1680.     printf("gluEndTrim(%#x);\n", nobj);
  1681.     GLU_CALL(gluEndTrim, (GLUnurbsObj *),(nobj));
  1682. }
  1683.  
  1684. const GLubyte *
  1685. gluErrorString(GLenum code)
  1686. {
  1687.     const GLubyte *result;
  1688.  
  1689.     gl_header();
  1690.     printf("gluErrorString(%d);\n", code);
  1691.     GLU_RCALL(const GLubyte *,gluErrorString, (GLenum ),(code));
  1692.     printf("/* gluErrorString returned %s */\n", result);
  1693.     return result;
  1694. }
  1695.  
  1696. GLUnurbsObj *
  1697. gluNewNurbsRenderer(void)
  1698. {
  1699.     GLUnurbsObj *result;
  1700.  
  1701.     gl_header();
  1702.     printf("gluNewNurbsRenderer();\n");
  1703.     GLU_RCALL(GLUnurbsObj *,gluNewNurbsRenderer, (),());
  1704.     printf("/* gluNewNurbsRenderer returned 0x%x */\n", result);
  1705.     return result;
  1706. }
  1707.  
  1708. GLUtriangulatorObj *
  1709. gluNewTess(void)
  1710. {
  1711.     GLUtriangulatorObj *result;
  1712.  
  1713.     gl_header();
  1714.     printf("gluNewTess();\n");
  1715.     GLU_RCALL(GLUtriangulatorObj*,gluNewTess, (),());
  1716.     printf("/* gluNewTess returned 0x%x */\n", result);
  1717.     return result;
  1718. }
  1719.  
  1720. void
  1721. gluNextContour(GLUtriangulatorObj *tobj, GLenum type)
  1722. {
  1723.     gl_header();
  1724.     printf("gluNextContour(%#x, %s);\n", tobj, gl_enum(type));
  1725.     GLU_CALL(gluNextContour, (GLUtriangulatorObj *,GLenum ),\
  1726.           (tobj,type));
  1727. }
  1728.  
  1729. void
  1730. gluNurbsCurve(GLUnurbsObj *nobj, GLint nknots, GLfloat *knot, GLint
  1731.           stride, GLfloat *ctlarray, GLint order, GLenum type)
  1732. {
  1733.     gl_header();
  1734.     printf("gluNurbsCurve(%#x, %d, ..., %d, ..., %d, %s);\n",
  1735.        nobj, nknots, stride, order, gl_enum(type));
  1736.     GLU_CALL(gluNurbsCurve, \
  1737.       (GLUnurbsObj *, GLint, GLfloat *, GLint, GLfloat *, GLint, GLenum ),\
  1738.          (nobj,nknots,knot,stride,ctlarray,order,type));
  1739. }
  1740.  
  1741. void
  1742. gluNurbsProperty(GLUnurbsObj *nobj, GLenum property, GLfloat value)
  1743. {
  1744.     gl_header();
  1745.     printf("gluNurbsProperty(%#x, %s, %g);\n", nobj, gl_enum(property), value);
  1746.     GLU_CALL(gluNurbsProperty, (GLUnurbsObj *, GLenum, GLfloat ),\
  1747.          (nobj,property,value));
  1748. }
  1749.  
  1750. void
  1751. gluNurbsSurface(GLUnurbsObj *nobj,
  1752.         GLint sknot_count, GLfloat *sknot,
  1753.         GLint tknot_count, GLfloat *tknot,
  1754.         GLint s_stride, GLint t_stride,
  1755.         GLfloat *ctlarray, GLint sorder, GLint torder, GLenum type)
  1756. {
  1757.  
  1758.     gl_header();
  1759.     printf("gluNurbsSurface(%#x, %d, ..., %d, ..., %d, %d, ..., %d, %d, %s);\n",
  1760.        nobj, sknot_count, tknot_count, s_stride, t_stride,
  1761.        sorder, torder, gl_enum(type));
  1762.     GLU_CALL(gluNurbsSurface,\
  1763.     (GLUnurbsObj*,GLint,GLfloat*,GLint,GLfloat*,GLint,GLint,GLfloat*,GLint,GLint,GLenum),\
  1764.          (nobj,sknot_count,sknot,tknot_count,tknot,s_stride,t_stride,ctlarray,sorder,torder,type));
  1765. }
  1766.  
  1767. void
  1768. gluPwlCurve(GLUnurbsObj *nobj, GLint count, GLfloat *array, GLint
  1769.         stride, GLenum type) 
  1770. {
  1771.     gl_header();
  1772.     printf("gluPwlCurve(%#x, %d, ..., %d, %s);\n",
  1773.        nobj, count, stride, gl_enum(type));
  1774.     GLU_CALL(gluPwlCurve, (GLUnurbsObj *, GLint, GLfloat *, GLint,GLenum),\
  1775.          (nobj,count,array,stride,type));
  1776. }
  1777.  
  1778. void
  1779. gluTessCallback(GLUtriangulatorObj *tobj, GLenum which, void (*func)())
  1780. {
  1781.     gl_header();
  1782.     printf("gluTessCallback(%#x, %s, %#x);\n", tobj, gl_enum(which), func);
  1783.     GLU_CALL(gluTessCallback,(GLUtriangulatorObj *, GLenum, void (*)()),\
  1784.          (tobj,which,func));
  1785. }
  1786.  
  1787. void
  1788. gluTessVertex(GLUtriangulatorObj *tobj, GLdouble v[3], void *data)
  1789. {
  1790.     gl_header();
  1791.     gl_defVecd(v, 3);
  1792.     printf("gluTessVertex(%#x, %s, %#x);\n", tobj, gl_printVecd(v, 3), data);
  1793.     GLU_CALL(gluTessVertex, (GLUtriangulatorObj *, GLdouble v[3], void *),\
  1794.          (tobj,v,data));
  1795. }
  1796.  
  1797. /******************************************************************/
  1798.  
  1799. #define GLX_CALL(name, argTypes, argVals) GL_CALL(name, argTypes, argVals)
  1800. #define GLX_RCALL(returnType, name, argTypes, argVals) \
  1801.     GL_RCALL(returnType, name, argTypes, argVals)
  1802.  
  1803. static void
  1804. _spitout_Attributes(int *attr)
  1805. {
  1806.     int counter = 0;
  1807.     while (attr[counter] != None) {
  1808.     switch(attr[counter++]) {
  1809.       case GLX_USE_GL:
  1810.         printf("GLX_USE_GL, ");
  1811.         break;
  1812.       case GLX_BUFFER_SIZE:
  1813.         printf("GLX_BUFFER_SIZE, %d, ", attr[counter++]);
  1814.         break;
  1815.       case GLX_LEVEL:
  1816.         printf("GLX_LEVEL, %d, ", attr[counter++]);
  1817.         break;
  1818.       case GLX_RGBA:
  1819.         printf("GLX_RGBA, ");
  1820.         break;
  1821.       case GLX_DOUBLEBUFFER:
  1822.         printf("GLX_DOUBLEBUFFER, ");
  1823.         break;
  1824.       case GLX_STEREO:
  1825.         printf("GLX_STEREO, ");
  1826.         break;
  1827.       case GLX_AUX_BUFFERS:
  1828.         printf("GLX_AUX_BUFFERS, %d, ", attr[counter++]);
  1829.         break;
  1830.       case GLX_RED_SIZE:
  1831.         printf("GLX_RED_SIZE, %d, ", attr[counter++]);
  1832.         break;
  1833.       case GLX_GREEN_SIZE:
  1834.         printf("GLX_GREEN_SIZE, %d, ", attr[counter++]);
  1835.         break;
  1836.       case GLX_BLUE_SIZE:
  1837.         printf("GLX_BLUE_SIZE, %d, ", attr[counter++]);
  1838.         break;
  1839.       case GLX_ALPHA_SIZE:
  1840.         printf("GLX_ALPHA_SIZE, %d, ", attr[counter++]);
  1841.         break;
  1842.       case GLX_DEPTH_SIZE:
  1843.         printf("GLX_DEPTH_SIZE, %d, ", attr[counter++]);
  1844.         break;
  1845.       case GLX_STENCIL_SIZE:
  1846.         printf("GLX_STENCIL_SIZE, %d, ", attr[counter++]);
  1847.         break;
  1848.       case GLX_ACCUM_RED_SIZE:
  1849.         printf("GLX_ACCUM_RED_SIZE, %d, ", attr[counter++]);
  1850.         break;
  1851.       case GLX_ACCUM_GREEN_SIZE:
  1852.         printf("GLX_ACCUM_GREEN_SIZE, %d, ", attr[counter++]);
  1853.         break;
  1854.       case GLX_ACCUM_BLUE_SIZE:
  1855.         printf("GLX_ACCUM_BLUE_SIZE, %d, ", attr[counter++]);
  1856.         break;
  1857.       case GLX_ACCUM_ALPHA_SIZE:
  1858.         printf("GLX_ACCUM_ALPHA_SIZE, %d, ", attr[counter++]);
  1859.         break;
  1860.       default:
  1861.         fprintf(stderr, "ACK! bad param in attribute list\n");
  1862.         break;
  1863.     }
  1864.     }
  1865.     printf("None\n");
  1866. }
  1867.  
  1868. XVisualInfo *
  1869. glXChooseVisual(Display *dpy, int screen, int *i)
  1870. {
  1871.     XVisualInfo *result;
  1872.  
  1873.     gl_header();
  1874.     printf("glXChooseVisual(0x%x, 0x%x,...);\n");
  1875.     _spitout_Attributes(i);
  1876.  
  1877.     GLX_RCALL(XVisualInfo*,glXChooseVisual, (Display*,int,int*),(dpy, screen, i));
  1878.     printf("/* glXChooseVisual returned 0x%x */\n", result);
  1879.     return result;
  1880. }
  1881.  
  1882. GLXContext
  1883. glXCreateContext(Display *dpy, XVisualInfo *i, GLXContext c, Bool b)
  1884. {
  1885.     GLXContext result;
  1886.  
  1887.     gl_header();
  1888.     printf("glXCreateContext(0x%x,0x%x,0x%x,%d);\n",
  1889.        dpy, i, c, b);
  1890.     GLX_RCALL(GLXContext,glXCreateContext, \
  1891.            (Display*,XVisualInfo*,GLXContext,Bool),(dpy,i,c,b));
  1892.     printf("/* glXCreateContext returned 0x%x */\n", result);
  1893.     return result;
  1894. }
  1895.  
  1896. GLXPixmap
  1897. glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, Pixmap pixmap)
  1898. {
  1899.     GLXPixmap result;
  1900.     gl_header();
  1901.     printf("glXCreateGLXPixmap(0x%x,0x%x,0x%x);\n",
  1902.        dpy,vis,pixmap);
  1903.     GLX_RCALL(GLXPixmap,glXCreateGLXPixmap, (Display*,XVisualInfo*,Pixmap),(dpy,vis,pixmap));
  1904.     printf("/* glXCreateGLXPixmap returned 0x%x */\n", result);
  1905.     return result;
  1906. }
  1907.  
  1908. void
  1909. glXDestroyContext(Display *dpy, GLXContext ctx)
  1910. {
  1911.     gl_header();
  1912.     printf("glXDestroyContext(0x%x,0x%x);\n", dpy, ctx);
  1913.     GLX_CALL(glXDestroyContext, (Display *, GLXContext),(dpy,ctx));
  1914. }
  1915.  
  1916. void
  1917. glXDestroyGLXPixmap(Display *dpy, GLXPixmap pix)
  1918. {
  1919.     gl_header();
  1920.     printf("glXDestroyGLXPixmap(0x%x,0x%x);\n", dpy, pix);
  1921.     GLX_CALL(glXDestroyGLXPixmap, (Display *, GLXPixmap),(dpy,pix));
  1922. }
  1923.  
  1924. int
  1925. glXGetConfig(Display *dpy, XVisualInfo *vis, int attrib, int *value)
  1926. {
  1927.     int result;
  1928.  
  1929.     gl_header();
  1930.     printf("glXGetConfig(0x%x, 0x%x, %d, 0x%x);\n",
  1931.        dpy,vis,attrib,value,result);
  1932.     GLX_RCALL(int, glXGetConfig, (Display*,XVisualInfo*,int,int*),(dpy,vis,attrib,value));
  1933.     printf("/* glXGetConfig returned %d */\n", result);
  1934.     return result;
  1935. }
  1936.  
  1937. Bool
  1938. glXMakeCurrent(Display *dpy, GLXDrawable d, GLXContext c)
  1939. {
  1940.     Bool result;
  1941.  
  1942.     gl_header();
  1943.     printf("glXMakeCurrent(0x%x,0x%x,0x%x);\n",
  1944.        dpy,d,c);
  1945.     GLX_RCALL(Bool,glXMakeCurrent, (Display*,GLXDrawable,GLXContext),(dpy,d,c));
  1946.     printf("/* glXMakeCurrent returned %d */\n", result);
  1947.     return result;
  1948. }
  1949.  
  1950. void
  1951. glXSwapBuffers(Display *dpy, GLXDrawable drawable)
  1952. {
  1953.     gl_header();
  1954.     printf("glXSwapBuffers(0x%x,0x%x);\n", dpy, drawable);
  1955.     GLX_CALL(glXSwapBuffers, (Display*,GLXDrawable),(dpy,drawable));
  1956. }
  1957.  
  1958.  
  1959.